<?php
/**
 * Created by PhpStorm.
 * User: sunfan
 * Date: 2017/2/4
 * Time: 13:58
 */

namespace Clientapi\Controller;

use Admin\Model\BusinessRangeModel;
use Admin\Model\CategoryModel;
use Admin\Model\ProductModel;

class IndexController extends MapiBaseController
{

    public function index(){

        $data = array();

        try{
            // 轮播图
            $data['banner'] = M("Focus")
                ->field('id,title,image,link_url,link_type,link_value')
                ->where(array('pos_id'=>1))
                ->select();

            $category = new CategoryModel();
            $data['category'] = $category ->
            join('onethink_picture ON icon = onethink_picture.id')->
            where(array('onethink_category.status'=>1,'is_food'=>1))->
            limit(4)->
            field('onethink_category.id,onethink_category.name,onethink_category.title,path as icon')->
            select();

            $busModel = new BusinessRangeModel();
            $data['business_area'] = $busModel
                ->where(array('is_hot'=>1,'order2'=>array('gt',0)))
                ->field('id,area_name,image_src,status')
                ->select();

            $meishi = new ProductModel();
            $data['recommand_food'] = $meishi ->
            where(array('tag_id'=>array('in','1,2')))->
            where(array('is_hot'=>1))->
            field('id,title,image,gprice,market_price')->
            select();
        }catch(\Exception $e){
            $this->ApiReturn(10002,'系统错误');
        }

        $this->ApiReturn(0, '成功', $data);
    }

}